(function () {

  /**
   * mode 1 新增, 2 编辑
   */
  function getFormBody(mode = '1')
  {
    return [
      {
        "type": "fieldSet",
        "title": "基本信息",
        "headingClassName": "bg-gray-100",
        "body": [
          {
            "type": "input-image",
            "name": "avatar",
            "size": "lg",
            "description": "上传尺寸：160x200px, 只能上传jpg、png，文件大小不超过2M",
            "label": "头像",
            "accept": ".jpg,.png",
            "receiver": "post:/b/site/upload?type=image",
          },
          {
            "type": "input-text",
            "size": "lg",
            "name": "name",
            "label": "姓名",
            "required": true
          },
          {
            "type": "input-number",
            "label": "年龄",
            "size": "lg",
            "name": "age",
            "validateOnChange": true,
            "validations": {
              "isInt": true,
              "minimum": 1,
            },
            "required": true
          },
          {
            "type": "radios",
            "name": "gender",
            "size": "lg",
            "label": '性别',
            "required": true,
            "options": [
              {
                "label": "男",
                "value": 1
              },
              {
                "label": "女",
                "value": 2
              }
            ]
          },
          {
            "name": "mobile",
            "type": "input-text",
            "size": "lg",
            "required": true,
            "validateOnChange": true,
            "validations": {
              "isPhoneNumber": true,
            },
            "label": "手机号码",
          },
          {
            "name": "region",
            "type": "chained-select",
            "label": "所在城市",
            "joinValues": false,
            "extractValue": false,
            "required": true,
            "source": "get:/b/region/chained?p_code=$parentId",
          },
          {
            "name": "consult_method",
            "type": "checkboxes",
            "label": "咨询方式",
            "required": true,
            "options": [
              {
                "label": "语音",
                "value": "1"
              },
              {
                "label": "视频",
                "value": "2"
              },
            ]
          },
          {
            "type": "radios",
            "name": "is_interpreter",
            "size": "lg",
            "label": '量表解读师',
            "required": true,
            "value": 2,
            "options": [
              {
                "label": "是",
                "value": 1
              },
              {
                "label": "否",
                "value": 2
              }
            ]
          },
          {
            "label": "职称",
            "type": "select",
            "size": "lg",
            "name": "title",
            "searchable": true,
            "clearable": true,
            "source": "get:/b/counselorT/maps?state=1",
          },
          // {
          //   "type": "input-text",
          //   "size": "lg",
          //   "name": "fan_number",
          //   "label": "粉丝数量",
          // },
          // {
          //   "type": "input-text",
          //   "size": "lg",
          //   "name": "visitor_number",
          //   "label": "访客数量",
          // },
          {
            "type": "input-text",
            "size": "lg",
            "name": "certificate_period",
            "label": "持证年限",
          },
          {
            "type": "input-text",
            "size": "lg",
            "name": "helped_number",
            "label": "帮助人数",
          },
          {
            "type": "input-text",
            "size": "lg",
            "name": "service_time",
            "label": "服务时长",
          },
        ]
      },
      {
        "type": "fieldSet",
        "title": "更多信息",
        "headingClassName": "bg-gray-100",
        "body": [
          {
            "name": "profile",
            "type": "textarea",
            "size": "lg",
            "label": "个人简介",
            "maxLength": 200,
            "placeholder": "最多200个字",
          },
          {
            "label": "教育背景",
            "type": "select",
            "size": "lg",
            "name": "edu",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorE/maps?state=1",
          },
          {
            "label": "专业资质",
            "type": "select",
            "size": "lg",
            "name": "qualifications",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorQ/maps?state=1",
          },
          {
            "label": "擅长领域",
            "type": "select",
            "size": "lg",
            "name": "expert",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorEx/maps?state=1",
          },
          {
            "label": "擅长人群",
            "type": "select",
            "size": "lg",
            "name": "crowd",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorC/maps?state=1",
          },
          {
            "label": "擅长服务",
            "type": "select",
            "size": "lg",
            "name": "service",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorS/maps?state=1",
          },
          {
            "label": "擅长流派",
            "type": "select",
            "size": "lg",
            "name": "sect",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorSe/maps?state=1",
          },
          {
            "label": "语言能力",
            "type": "select",
            "size": "lg",
            "name": "language",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorL/maps?state=1",
          },
          {
            "label": "咨询风格",
            "type": "select",
            "size": "lg",
            "name": "style",
            "searchable": true,
            "clearable": true,
            "multiple": true,
            "source": "get:/b/counselorSt/maps?state=1",
          },
          {
            "name": "expert_intro",
            "type": "textarea",
            "size": "lg",
            "label": "擅长领域介绍",
            "maxLength": 200,
            "placeholder": "最多200个字",
          },
          {
            "name": "style_intro",
            "type": "textarea",
            "size": "lg",
            "label": "咨询风格介绍",
            "maxLength": 200,
            "placeholder": "最多200个字",
          },
          {
            "type": "combo",
            "label": "培训情况",
            "name": "training",
            "multiLine": true,
            "multiple": true,
            "value": [
              {}
            ],
            "items": [
              {
                "type": "input-date-range",
                "name": "training_experience",
                "label": "培训经历",
                "size": "lg",
                "required": true
              },
              {
                "name": "training_content",
                "label": "培训内容",
                "type": "input-text",
                "size": "lg",
                "required": true
              },
            ]
          },
        ]
      },
    ];
  }

  function getExpertFormBody(mode = '1') {
    return [
      {
        "type": "fieldSet",
        "title": "基本信息",
        "headingClassName": "bg-gray-100",
        "body": [
          {
            "type": "hidden",
            "name": "expert_id"
          },
          {
            "type": "input-text",
            "size": "lg",
            "name": "name",
            "label": "项目标题",
            "required": true
          },
          {
            "type": "input-number",
            "label": "项目金额(元)",
            "size": "lg",
            "name": "amount",
            "required": true,
            "validateOnChange": true,
            "validations": {
              "minimum": 0,
              "maximum": 9999999999,
            },
          },
          {
            "name": "intro",
            "type": "textarea",
            "size": "lg",
            "label": "项目介绍",
            "maxLength": 200,
            "placeholder": "最多200个字",
          },
        ]
      }
    ]
  }

  return {
    "type": "page",
    "initApi": "/b/permits/init",
    "title": "专家列表",
    "toolbar": [
      {
        "type": "button",
        "actionType": "drawer",
        "label": "新增",
        "visibleOn": "isInArray(this.front_end, 'scale_category_save')",
        "icon": "fa fa-plus pull-left",
        "primary": true,
        "drawer": {
          "title": "新增",
          "closeOnOutside": true,
          "closeOnEsc": true,
          "resizable": true,
          "position": "right",
          "size": "lg",
          "body": {
            "type": "form",
            // "debug": true,
            "persistData": "user_expert_insert",
            "clearPersistDataAfterSubmit": true,
            "name": "新增表单",
            "api": "post:/b/expert/save",
            "controls": getFormBody(),
          }
        }
      }
    ],
    "body": {
      "type": "crud",
      "className": "break-all",
      "hideQuickSaveBtn": true,
      "api": "get:/b/expert/index",
      "quickSaveApi": "post:/b/expert/batch",
      "quickSaveItemApi": "post:/b/expert/item?id=$id",
      // "itemCheckableOn": "this.is_super !== 1 && this.leader_count === 0",
      "perPage": 10,
      "keepItemSelectionOnPageChange": true,
      "maxKeepItemSelectionLength": 20,
      "pageField": "page",
      "perPageField": "page_size",
      "labelTpl": "${name}",
      "syncLocation": false,
      "filter": {
        "title": "条件搜索",
        "submitText": "搜索",
        "controls": [
          {
            "label": "姓名：",
            "type": "text",
            "size": "sm",
            "name": "name",
            "placeholder": "请输入"
          },
          {
            "type": "select",
            "name": "gender",
            "size": "sm",
            "label": '性别',
            "searchable": true,
            "clearable": true,
            "options": [
              {
                "label": "男",
                "value": 1
              },
              {
                "label": "女",
                "value": 2
              }
            ]
          },
          {
            "label": "手机号码：",
            "type": "text",
            "size": "sm",
            "name": "mobile",
            "placeholder": "请输入"
          },
          {
            "label": "职称",
            "type": "select",
            "size": "sm",
            "name": "title",
            "searchable": true,
            "clearable": true,
            "source": "get:/b/counselorT/maps?state=1",
          },
        ],
        "actions": [
          {
            "type": "button",
            "actionType": "clear",
            "label": "重置"
          },
          {
            "type": "button",
            "actionType": "submit",
            "label": "搜索",
            "level": "primary",
          }
        ]
      },
      "bulkActions": [
        // {
        //   "label": "批量删除",
        //   "visibleOn": "isInArray(this.front_end, 'admin_list_delete')",
        //   "level": "danger",
        //   "actionType": "ajax",
        //   "api": "post:/b/admin/del/${ids|raw}",
        //   "confirmText": "确定要批量删除?"
        // }
      ],
      "filterTogglable": true,
      "headerToolbar": [
        "filter-toggler",
        "bulkActions",
        {
          "type": "columns-toggler",
          "align": "right"
        },
        {
          "type": "pagination",
          "align": "right"
        }
      ],
      "footerToolbar": [
        "statistics",
        "switch-per-page",
        "pagination"
      ],
      "columns": [
        {
          "name": "id",
          "label": "ID",
          "hidden": true,
          "sortable": true,
          "type": "text",
          "toggled": true
        },
        {
          "name": "name",
          "fixed": "left",
          "label": "姓名",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "gender_map",
          "label": "性别",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "mobile",
          "label": "手机号码",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "is_interpreter_map",
          "label": "量表解读师",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "title",
          "label": "职称",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "certificate_period",
          "label": "持证年限",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "helped_number",
          "label": "帮助人数",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "service_time",
          "label": "服务时长",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        {
          "name": "state",
          // "width": 50,
          "type": "switch",
          "label": "禁用/启用",
          "trueValue": 1,
          "falseValue": 2,
          "quickEdit": {
            "type": "switch",
            "trueValue": 1,
            "falseValue": 2,
            "mode": "inline",
            "saveImmediately": true,
          },
        },
        {
          "name": "creator",
          "label": "创建人",
          "type": "text",
          "sortable": false,
          "toggled": true
        },
        {
          "name": "created_at",
          "label": "创建时间",
          "type": "text",
          "sortable": false,
          "toggled": true
        },
        {
          "type": "operation",
          "fixed": "right",
          "label": "操作",
          "buttons": [
            {
              "type": "button",
              "label": "编辑",
              "visibleOn": "isInArray(this.front_end, 'scale_category_update')",
              "level": "primary",
              "actionType": "drawer",
              "drawer": {
                "position": "right",
                "size": "lg",
                "title": "编辑",
                "closeOnOutside": true,
                "closeOnEsc": true,
                "resizable": true,
                "body": {
                  "type": "form",
                  // "debug": true,
                  "name": "编辑",
                  "api": "post:/b/expert/update?id=$id",
                  "controls": getFormBody('2')
                }
              }
            },
            {
              "type": "action",
              "label": "设置项目",
              // "visibleOn": "isInArray(this.front_end, 'company_list_contract')",
              "level": "primary",
              "actionType": "drawer",
              "drawer": {
                "title": "设置项目",
                "closeOnOutside": true,
                "closeOnEsc": true,
                "resizable": true,
                "position": "right",
                "size": "xl",
                "close": false,
                "actions": [
                  {
                    "type": "button",
                    "actionType": "close",
                    "label": "关闭",
                    "primary": false
                  }
                ],
                "data": {
                  "expert_id": "${id}",
                },
                "body": {
                  "type": "crud",
                  "hideQuickSaveBtn": true,
                  "api": "get:/b/expertI/index",
                  "quickSaveApi": "post:/b/expertI/batch",
                  "quickSaveItemApi": "post:/b/expertI/item?id=$id",
                  "perPage": 10,
                  "keepItemSelectionOnPageChange": true,
                  "maxKeepItemSelectionLength": 20,
                  "pageField": "page",
                  "perPageField": "page_size",
                  "labelTpl": "${name}",
                  "syncLocation": false,
                  "filter": {
                    "title": "条件搜索",
                    // "debug": true,
                    "submitText": "搜索",
                    "controls": [
                      {
                        "type": "hidden",
                        "name": "expert_id"
                      },
                      {
                        "label": "项目标题：",
                        "type": "text",
                        "size": "sm",
                        "name": "name",
                        "placeholder": "请输入"
                      },
                    ],
                    "actions": [
                      {
                        "type": "button",
                        "actionType": "clear",
                        "label": "重置"
                      },
                      {
                        "type": "button",
                        "actionType": "submit",
                        "label": "搜索",
                        "level": "primary",
                      }
                    ]
                  },
                  "bulkActions": [
                    // {
                    //   "label": "批量删除",
                    //   // "visibleOn": "this.front_end.includes('system_role_delete')",
                    //   "level": "danger",
                    //   "actionType": "ajax",
                    //   "api": "post:/b/contract/del/${ids|raw}",
                    //   "confirmText": "确定要批量删除?"
                    // }
                  ],
                  "filterTogglable": true,
                  "headerToolbar": [
                    "filter-toggler",
                    "bulkActions",
                    {
                      "type": "button",
                      "actionType": "drawer",
                      "label": "新增",
                      // "visibleOn": "this.front_end.includes('system_role_save')",
                      "icon": "fa fa-plus pull-left",
                      "primary": true,
                      "drawer": {
                        "title": "新增",
                        "closeOnOutside": true,
                        "closeOnEsc": true,
                        "resizable": true,
                        "position": "right",
                        "size": "lg",
                        "body": {
                          "type": "form",
                          // "debug": true,
                          "persistData": "expert_item_insert",
                          "clearPersistDataAfterSubmit": true,
                          "mode": "horizontal",
                          "api": {
                            "method": "post",
                            'url': "/b/expertI/save",
                            "dataType": "form"
                          },
                          "controls": getExpertFormBody('1')
                        },
                      }
                    },
                    {
                      "type": "columns-toggler",
                      "align": "right"
                    },
                    {
                      "type": "pagination",
                      "align": "right"
                    }
                  ],
                  "footerToolbar": [
                    "statistics",
                    "switch-per-page",
                    "pagination"
                  ],
                  "columns": [
                    {
                      "name": "id",
                      "label": "ID",
                      "width": 50,
                      "sortable": true,
                      "hidden": true,
                      "type": "text",
                      "toggled": true
                    },
                    {
                      "name": "name",
                      "label": "项目标题",
                      "sortable": false,
                      "searchable": true,
                      "type": "text",
                      "toggled": true,
                    },
                    {
                      "name": "amount",
                      "label": "项目金额(元)",
                      "sortable": false,
                      "searchable": true,
                      "type": "text",
                      "toggled": true,
                    },
                    {
                      "name": "creator",
                      "label": "创建人",
                      "type": "text",
                      "sortable": false,
                      "toggled": true
                    },
                    {
                      "name": "created_at",
                      "label": "创建时间",
                      "type": "text",
                      "sortable": true,
                      "toggled": true
                    },
                    {
                      "type": "operation",
                      "label": "操作",
                      "buttons": [
                        {
                          "type": "button",
                          "label": "编辑",
                          // "visibleOn": "this.front_end.includes('system_role_update')",
                          "level": "info",
                          "actionType": "drawer",
                          "drawer": {
                            "position": "right",
                            "size": "lg",
                            "title": "编辑",
                            "closeOnOutside": true,
                            "closeOnEsc": true,
                            "resizable": true,
                            "body": {
                              "type": "form",
                              "api": "post:/b/expertI/update?id=$id",
                              "mode": "horizontal",
                              "controls": getExpertFormBody('2')
                            },
                          },
                        },
                        {
                          "type": "button",
                          "label": "删除",
                          // "visibleOn": "this.front_end.includes('system_role_delete')",
                          "level": "danger",
                          "actionType": "ajax",
                          "confirmText": "您确认要删除?",
                          "api": "post:/b/expertI/delete?ids=$id&expert_id=$expert_id"
                        }
                      ],
                      "toggled": true
                    }
                  ]
                }
              },
            },
          ],
          "toggled": true
        }
      ]
    }
  };
})();